<!--  -->
<template>
  <div class="update-birthday">

    <van-datetime-picker
  v-model="currentDate"
  type="date"
  title="选择年月日"
  :min-date="minDate"
  :max-date="maxDate"
  @cancel="$emit('close')"
  @confirm="onConfirm"
/>
  </div>
 
</template>

<script>
import { updateUserProfile } from '@/api/user'
import   dayjs from 'dayjs'
export default {
  name:'UpdateBirthday',
  components: {},
  props:{
    value:{
      type:[String,Object],
      require:true
    }
  },
  data () {
  return {
     
      minDate: new Date(1920, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(this.value),
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
   async onConfirm(value){

    console.log(value)
     this.$toast.loading({
       message:'保存中',
       forbidClick:true  //禁止背景点击
     })
  const  datetime1=dayjs(value).format('YYYY-MM-DD')
    console.log(datetime1);
     try {
       const {data}=await updateUserProfile({
        
       birthday:datetime1
     })
      this.$toast.success('保存成功')
      // this.$emit('update-name',this.localName)
     this.$emit('input',datetime1)
     //更新成功->修改父组件->关闭弹出层
     this.$emit('close')
       
     } catch (error) {
         if(error&&error.response&&error.response.status===409){
            this.$toast.fail('呢称已存在')
         }
     }
     
    }
  }
}

</script>
<style lang='less' scoped>
.name-field-wrap{
  padding: 10px;
}
</style>